package cn.com.servletconfig;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "sConfig", value = "/sConfig", initParams = {@WebInitParam(name = "username", value = "黄艳贞"),
        @WebInitParam(name = "password", value = "123456")})
public class sConfig extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        // 获取ServletConfig对象，该对象包含了Servlet的初始化参数信息
        ServletConfig config = this.getServletConfig();

        // 从Servlet配置中获取名为"username"的初始化参数值
        String username = config.getInitParameter("username");

        // 从Servlet配置中获取名为"password"的初始化参数值
        String password = config.getInitParameter("password");

        // 获取PrintWriter对象，用于向客户端输出响应内容
        PrintWriter out = response.getWriter();

        // 向客户端输出用户名信息，并添加HTML换行标签
        out.println("用户名：" + username + "<br/>");

        // 向客户端输出密码信息，并添加HTML换行标签
        out.println("密码：" + password + "<br/>");

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }


}
